<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>X5</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css"/>
    <link rel="stylesheet" type="text/css" href="../css/aui_skin_night.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>

    <style>
        .display-block {
            display: block;
        }

        .display-none {
            display: none;
        }

        .icon-svip {
            width: 20px;
            margin: -10px 10px 0 0;

            content: '';
            background: url() no-repeat;

            height: 20px;
            background-size: contain;
            display: inline-block;
            vertical-align: middle;

        }

        .cart {
            z-index: 18;
            bottom: 0;
            height: 50px;
            width: 100%;
            background: #3c3c3c;
        }

        .loca, aside, .cart, .sele {
            position: fixed;
            left: 0;
            z-index: 9;
        }

        .cart .r {
            float: right;
            width: 36%;
            background: #5c5c5c;
            text-align: center;
            color: #FFF;
            font-size: 12px;
        }

        .cart .r_ok {
            float: right;
            width: 36%;
            background: #1b7dff;
            text-align: center;
            color: #FFF;
            font-size: 15px;
        }

        .cart > div {
            line-height: 50px;
            font-size: 16px;
            color: #fff;
        }

        a, a:hover, a:active, a:focus {
            text-decoration: none;
        }

        .cart .l {
            /*    width: 42%;  */
            position: relative;
            padding-left: 15%;
        }

        .cart .cartnum {
            position: absolute;
            display: inline-block;
            font-style: normal;
            background: #ff0000;
            font-size: 12px;
            height: 16px;
            left: 50px;
            top: 4px;
            color: #ffffff;
            border-radius: 10px;
            padding: 1px 6px;
            z-index: 2;
            line-height: 16px;
        }

        .cart img {
            position: absolute;
            padding: 5px;
            height: 35px;
            background: #3c3c3c;
            z-index: 1;
            left: 10px;
            top: 5px;
        }


    </style>

</head>
<body>

<header class="aui-bar aui-bar-nav fix-statusbar" style="background: linear-gradient(to right,#03bbf4 0,#d800ff 250%)"; >
    <a class="aui-pull-left" onclick="GoBack()">
        返回
    </a>

    <a class="aui-pull-left" onclick="GoPageWork('Refresh')">
        <!--<span class="aui-iconfont aui-icon-refresh"></span>-->
    </a>

    <a class="aui-pull-left" onclick="GoPageWork('Close')">
        <!--<span class="aui-iconfont aui-icon-close"></span>-->
    </a>

    <div class="aui-title" id="title" style="font-size: 15px;"><i class="icon-svip"></i> 影视特权</div>

    <a id="GoPlay" class="display-none " onclick="PlayButtonNav()">
        <!--<span style=" color: #d29039; font-size:10px;margin-right: 5px;"  id="GoPlayText"> 选线播放 </span> <span class="aui-iconfont aui-icon-video" style=" color: #d29039; font-weight: bold;"></span>-->
    </a>


    <a class="aui-pull-right" onclick="GoPageWork('Close')">
        关闭
    </a>
</header>

<div class="cart ng-scope" id="bottom_button_click">
    <div class="r" id="bottom_button_status">正在等待资源</div>
    <div class="l ng-binding">
        <label id="type_title" style="font-size: 12px;">VIP 连接中 ···</label>
    </div>
    <a><img src=""
            alt="..."></a>
</div>


</body>
<!--<script type="text/javascript" src="../js/zepto.js"></script>-->
<script type="text/javascript" src="../js/zepto5.js"></script>
<script type="text/javascript" src="../js/api.js"></script>
<script type="text/javascript">

    var browser;
    var play_url = '';
    var play_title = '';


    apiready = function () {

        var api_url = localStorage.getItem('api_url');
        var user_id = localStorage.getItem('user_id');
        if (user_id > 1) {
            api.ajax({
                url: api_url + '/login/login/imei.html',
                method: 'get',
                data: {
                    values: {
                        uid: user_id,
                        mike_key: localStorage.getItem('mike_key')
                    }
                }
            }, function (ret, err) {
                if (ret) {
                    localStorage.setItem('jx_url1', ret.msg.url1);
                    localStorage.setItem('jx_url2', ret.msg.url2);
                    localStorage.setItem('jx_url3', ret.msg.url3);
                    localStorage.setItem('jx_url4', ret.msg.url4);
                    localStorage.setItem('jx_url5', ret.msg.url5);
                    localStorage.setItem('jx_url6', ret.msg.url6);
                    localStorage.setItem('jx_url7', ret.msg.url7);
                    localStorage.setItem('jx_url8', ret.msg.url8);
                    localStorage.setItem('jx_url9', ret.msg.url9);
                    localStorage.setItem('jx_url10', ret.msg.url10);
                    if (ret.msg.imei != api.deviceId) {
                        localStorage.setItem('user_id', '');
                        localStorage.setItem('user_name', '');
                        localStorage.setItem('user_time', '');
                        api.sendEvent({
                            name: 'newLoingdata',
                            extra: {}
                        });
                        api.closeWin({});
                        api.alert({
                            title: '您已在其他设备登陆！账号已强制下线',
                            msg: '请重新登陆',
                        });
                        clearInterval(ddtimer); //清除定时器
                        return;
                    }
                } else {

                }
            });
        }


        //	alert(JSON.stringify(localStorage.getItem('jx_Interface_one') ));
        //系统返回键是否绑定
        // if (localStorage.getItem('SystemReturnKeyBinding') == 1) {
        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            GoBack();
        });
        // }
        browser = api.require('webBrowser');
        var headerHeight = $('header').height();
        console.log("url:" + api.pageParam.url);
        browser.openView({
            url: api.pageParam.url,
            //  url:'https://tool.lu/useragent',
            progress: {
                color: "#000",	//加载进度条颜色，支持 rgb，rgba，#fff等，默认值#45C01A
                height: 1		 //进度条高度，默认值3，数字类型
            },
            rect: {
                x: 0,
                y: headerHeight,
                w: 'auto',
                h: api.winHeight - headerHeight - 50
            }
        }, function (ret, err) {
            switch (ret.state) {
                case 0:		//0-开始加载；
                    console.log('state  为 0  开始加载！ 当前URL:' + ret.url);
                    //链接处理
                    if (ret.url.indexOf("v.qq.com") != -1) {
                        //底部按钮 来源名称
                        BottomButtonShowName('Tencent');
                        //头部按钮
                        // PlayButtonShow(9);
                        // BottomButtonShow(1);
                        var obj = document.getElementById("bottom_button_status");
                        obj.setAttribute("class", 'r_ok');
                        var obj = document.getElementById("bottom_button_click");
                        //	obj.setAttribute("onclick", "GoBottomButtonPlay(1);");
                        obj.setAttribute("onclick", 'GoBottomButtonPlay(1);');
                        bottom_button_status.innerHTML = '开始播放';

                        // var ago_key = localStorage.getItem('tx_play_decide');
                        var ago_key = 'L3BsYXksL20vLC94LywvY292ZXIv';
                        // var end_key = U.signature(ago_key);
                        var end_key = "/play,/m/,/x/,/cover/";
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {
                                //底部按钮
                                play_url = ret.url;
                                // BottomButtonShow(1, ret.url);

                                //腾讯如果进主页--在进专属VIP---获取的链接大部分解析接口不支持
                                //https://m.v.qq.com/x/cover/t/tk3l27paq7sqr0z.html--异常
                                //https://m.v.qq.com/x/cover/tk3l27paq7sqr0z.html--异常
                                //https://m.v.qq.com/cover/t/tk3l27paq7sqr0z.html--正常
                                //https://v.qq.com/x/cover/tk3l27paq7sqr0z/p0036mrfj8h.html--电脑端
                                //alert('原始URL：'+play_url)

                                //处理删掉 /x/
                               //var a="/x/cover/t/"
                               //if(play_url.indexOf(a) != -1){// true
                               //    var e=play_url.split('/x/')
                               //    play_url=e.join('/')
                               //}

                                //处理添加 /t/
                                //var b="/x/cover/"
                                //var d="/cover/t/"
                                //if(play_url.indexOf(b) != -1&&play_url.indexOf(d) == -1){// true
                                //    var f=play_url.split(b)
                                //    play_url=f.join('/cover/t/')
                                //}

                                //处理选集异常问题--手机端偶尔会丢失vid 只有cid所以一直播放第一集
                                //https://m.v.qq.com/x/m/play?cid=mzc002003vpbryd&vid=
                                play_url=MikeToUrl(play_url);
                                //alert('处理后的URL：'+play_url)
                                break;
                            } else {
                                //头部按钮
                                // PlayButtonShow(1);
                                //底部按钮
                                // BottomButtonShow(1);
                            }
                        }
                    }
                    else if (ret.url.indexOf("m.iqiyi.com") != -1) {
                        //底部按钮 来源名称
                        BottomButtonShowName('iQIYI');
                        // var ago_key = localStorage.getItem('iqy_play_decide');
                        var ago_key = 'dl8=';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {
                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);
                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);
                            }
                        }
                    }
                    else if (ret.url.indexOf("pptv.com") != -1) {
                        //底部按钮 来源名称
                        BottomButtonShowName('PPTV');

                        // var ago_key = localStorage.getItem('pptv_play_decide');
                        var ago_key = 'L3Nob3cv';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {

                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);

                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);


                            }
                        }

                    }
                    else if (ret.url.indexOf("youku.com") != -1) {
                        //底部按钮 来源名称
                        BottomButtonShowName('YOUKU');
                        // var ago_key = localStorage.getItem('yk_play_decide');
                        var ago_key = 'L2FsaXBheV92aWRlby8sL3ZpZGVvLw==';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {

                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);

                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);
                            }
                        }

                    }
                    else if (ret.url.indexOf("m.fun.tv") != -1) {

                        //底部按钮 来源名称
                        BottomButtonShowName('FUNTV');

                        // var ago_key = localStorage.getItem('fx_play_decide');
                        var ago_key = 'L21wbGF5Lw==';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {

                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);

                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);


                            }
                        }

                    }
                    else if (ret.url.indexOf("1905.com") != -1) {

                        //底部按钮 来源名称
                        BottomButtonShowName('1905');

                        // var ago_key = localStorage.getItem('m1905_play_decide');
                        var ago_key = 'L3BsYXkv';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {

                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);

                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);


                            }
                        }

                    }
                    else if (ret.url.indexOf("miguvideo.com") != -1) {

                        //底部按钮 来源名称
                        BottomButtonShowName('MIGU');

                        // var ago_key = localStorage.getItem('migu_play_decide');
                        var ago_key = 'L2RldGFpbA==';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {

                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);

                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);


                            }
                        }

                    }
                    else if (ret.url.indexOf("sohu.com") != -1) {
                        //底部按钮 来源名称
                        BottomButtonShowName('SOHU');
                        // var ago_key = localStorage.getItem('sohu_play_decide');
                        var ago_key = 'Y2hhbm5lbGVk';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {
                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);
                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);
                            }
                        }
                    }
                    else if (ret.url.indexOf("bilibili.com") != -1) {
                        play_url = ret.url;
                        //底部按钮 来源名称
                        BottomButtonShowName('BILBILI');
                        //头部按钮
                        PlayButtonShow(1);
                        //底部按钮
                        play_url = ret.url;
                        BottomButtonShow(1, ret.url);
                    }
                    else if (ret.url.indexOf("m.mgtv.com") != -1) {
                        //底部按钮 来源名称
                        BottomButtonShowName('MGTV');
                        // var ago_key = localStorage.getItem('mg_play_decide');
                        var ago_key = 'L2Iv';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {

                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);

                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);

                            }
                        }
                    }
                    break;
                case 1:		//1-加载进度发生变化；
                    break;
                case 2:		//2-结束加载；
                    console.log('state  为 2  结束加载！ 当前URL:' + ret.url);
                    break;
                case 3:		//3-title发生变化
                    console.log('state  为 3  title发生变化！ 当前title:' + ret.title);
                    title.innerHTML = '<i class="icon-svip"></i>' + ret.title;
                    // U.setStorage('Play_title', ret.title);
                    localStorage.setItem('Play_title',  ret.title);
                    break;
                case 4:		//4-url发生变化
                    console.log('state  为 4  url发生变化！ 当前url:' + ret.url);
                    if (ret.url.indexOf("m.mgtv.com") != -1) {
                        //底部按钮 来源名称
                        BottomButtonShowName('MGTV');
                        // var ago_key = localStorage.getItem('mg_play_decide');
                        var ago_key = 'L2Iv';
                        var end_key = U.signature(ago_key);
                        console.log(' base64Decode: ' + end_key);
                        decode_key = end_key.split(',');
                        for (var i = 0; i < decode_key.length; i++) {
                            if (ret.url.indexOf(decode_key[i]) != -1) {
                                //头部按钮
                                PlayButtonShow(1);
                                //底部按钮
                                play_url = ret.url;
                                BottomButtonShow(1, ret.url);

                                break;
                            } else {
                                //头部按钮
                                PlayButtonShow(0);
                                //底部按钮
                                BottomButtonShow(0);

                            }
                        }
                    }
                    BottomButtonShow(1);
                    break;
                default:
                    break;
            }
        });
    }

    function MikeToUrl(strMatch){
        //var strMatch="https://m.v.qq.com/x/m/play?cid=mzc00200x9fxrc9&vid=g0035k8m858"
        if (strMatch.indexOf("cid=") != -1&&strMatch.indexOf("&vid=") != -1) {
            var matchReg = /\(?<=cid=\).*?\&vid/;
            var matchReg2 = /\(?<=&vid=\).*/;
            var cid=strMatch.match(matchReg)[0].slice(0,-4);
            var vid=strMatch.match(matchReg2)[0];
            vid=vid.slice(0,11)
            if(vid.length>10){
                //判断取出来的VID是否规范
                var zg =  /^[0-9a-zA-Z]*$/;
                if(zg.test(vid)){
                    strMatch="https://v.qq.com/x/cover/"+cid+"/"+vid+".html";
                }
            }
        }
        return strMatch;
    }

    //播放按钮 显示
    function PlayButtonShow(type) {

        if (type == 1) {

            var obj = document.getElementById("GoPlay");
            obj.setAttribute("class", 'aui-pull-right display-block');

        } else if (type == 9) {

            var obj = document.getElementById("GoPlay");
            obj.setAttribute("class", 'aui-pull-right display-block');

            var obj = document.getElementById("GoPlay");
            //	obj.setAttribute("onclick", "GoBottomButtonPlay(1);");
            obj.setAttribute("onclick", "GoPageWork('Refresh');");

            GoPlayText.innerHTML = ' 获取资源';
        } else {

            var obj = document.getElementById("GoPlay");
            obj.setAttribute("class", 'display-none');
        }

    }

    //导航播放按钮点击
    function PlayButtonNav() {


        console.log("导航播放按钮点击url:" + play_url);

        //	GetInfoAgoTitle = U.GetInfoAgo(play_url,play_title);
        //	play_title = GetInfoAgoTitle[0];


        //	U.PlayTips(1,play_title,play_url);
        browser.loadScript({
            script: 'location.reload();'
        });

        U.OpenVideoJxPopup(play_url);

    }


    //连接状态 NAME 底部 显示
    function BottomButtonShowName(name) {
        //	if(name == 'Tencent'){
        //							type_title.innerHTML = ' 请先点击右上角获取资源！';
        //		}else{

        type_title.innerHTML = name + ' VIP 已连接成功！';
        //		}

    }

    //播放按钮  底部 显示
    function BottomButtonShow(type) {

        if (type == 1) {
            //底部
            var obj = document.getElementById("bottom_button_status");
            obj.setAttribute("class", 'r_ok');

            var obj = document.getElementById("bottom_button_click");
            //	obj.setAttribute("onclick", "GoBottomButtonPlay(1);");
            obj.setAttribute("onclick", 'GoBottomButtonPlay(1);');

            bottom_button_status.innerHTML = '开始播放';

        } else {
            //底部
            var obj = document.getElementById("bottom_button_status");
            obj.setAttribute("class", 'r');

            var obj = document.getElementById("bottom_button_click");
            obj.setAttribute("onclick", 'GoBottomButtonPlay(0);');

            bottom_button_status.innerHTML = '正在等待资源';

        }

    }


    //底部按钮点击
    function GoBottomButtonPlay(type) {
        //	alert(JSON.stringify(play_url));
        if (type == 1) {
            GoPageWork('Refresh');
            U.toast('努力加载中 请稍等···');
            setTimeout(function () {		//延迟执行
                if (localStorage.getItem('jx_url2') != null || localStorage.getItem('jx_url2') != '' || localStorage.getItem('jx_url2') != 'undefined') {

                    var Composite_Url = localStorage.getItem('jx_url2') + play_url;
                    //alert(JSON.stringify('1 可以播放 组合地址： '+ Composite_Url ));
                    console.log(' 接口一不为空 当前组合地址: ' + Composite_Url);
                    console.log(' 准备提交播放');

                    //处理投屏/ios兼容 m119-- 1投屏 2不投屏
                    if (localStorage.getItem('m119')==2||api.systemType == 'ios'){
                        var s_name="play_win_w";
                        var s_url="./play_win_w.html";
                    }else{
                        var s_name="play_win_y";
                        var s_url="./play_win_y.html";
                    }
                    api.openWin({
                        name: s_name,
                        url: s_url,
                        delay: 300,
                        pageParam: {
                            url: Composite_Url,
                            srcUrl: play_url,
                            title: localStorage.getItem('Play_title'),
                            needRecordHistory: true
                        },
                        //pageParam:{url:dataurl2},
                        bgColor: '#000000'
                    })

                    /*

                    if (localStorage.getItem('m119')==2||api.systemType == 'ios'){
                        api.openWin({
                            name: 'play_win_w',
                            url: './play_win_w.html',
                            delay: 300,
                            pageParam: {
                                url: Composite_Url,
                                srcUrl: play_url,
                                title: localStorage.getItem('Play_title'),
                                needRecordHistory: true
                            },
                            //pageParam:{url:dataurl2},
                            bgColor: '#000000'
                        });
                    }else{
                        api.openWin({
                            name: 'play_win_y',
                            url: './play_win_y.html',
                            delay: 300,
                            pageParam: {
                                url: Composite_Url,
                                srcUrl: play_url,
                                title: localStorage.getItem('Play_title'),
                                needRecordHistory: true
                            },
                            //pageParam:{url:dataurl2},
                            bgColor: '#000000'
                        });
                    }

                    */



                }
            }, 1200);


        } else {
            U.toast('当前页面找不到可播放资源');
        }

    }


    //开始播放 （弹窗提示）
    function GoPlay(url) {
        // alert(JSON.stringify(play_title));
        // U.openWin('video/', 'videos_play_jiexi',{url:play_url,title:play_title});
        U.PlayTips(1, play_title, url);

    }


    //返回处理
    function GoBack() {

        // if (localStorage.getItem('WebReturnLogic') == 1) {
        //     GoPageWork('Back')
        // } else {
        //     GoPageWork('Close')
        // }
        GoPageWork('Back')
    }
    //页面处理
    function GoPageWork(name) {

        if (name == 'Back') {

            browser.historyBack(
                function (ret, err) {
                    if (!ret.status) {
                        api.closeWin();
                    }
                }
            );

        } else if (name == 'Close') {

            api.closeWin();


        } else if (name == 'Refresh') {

            browser.loadScript({
                script: 'location.reload();'
            });

        } else if (name == 'Gear') {

            U.openWin('my/', 'setlist');

        }


    }

</script>
</html>
